<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tag/c.tld"%>
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>代码生成器</title>
	<%@ include file="include/style.jsp"%>
	<%@ include file="include/js.jsp"%>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-paging.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-table.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-form.js"></script>
</head>
<body>
<div class="container">
	<div class="panel panel-default">
		<div class="panel-header clearfix">
			<button id="btnAddProject" class="btn btn-success pull-right" style="margin:5px;">添加新项目</button>
		</div>
		<div class="panel-body">
			<table id="tableProjectList" class="table table-border table-hover"></table>
		</div><!-- /.panel-body -->
	</div><!-- /.panel -->
</div><!-- /.container -->
<script type="text/javascript">
$(function(){
	
	var plugConfigClick = function(record){
		jf.modal('功能插件','${webRoot}/plugConfig',{code:record.projectCode},function(){
			$('#tableProjectList').jfTable('loadData');
			$(this).modal('hide');
		});
	};

	$('#tableProjectList').jfTable({
		pagingEl:null,
		ajax:{
			url:'${webRoot}/project/data'
		},
		cols:[{
			code:'projectCode',
			title:'项目代码'
		},{
			code:'projectName',
			title:'项目名称'
		},{
			code:'projectType',
			title:'项目类型'
		},{
			code:'projectPackage',
			title:'项目包路径'
		},{
			title:'数据库配置',
			format:function(record){
				if(record.configDb == true){
					return '<a href="${webRoot}/dbConfig?code='+record.projectCode+'">已配置</a>';
				}else{
					return $('<a href="javascript:void(0);">未配置</a>').click(function(){
						jf.alert("数据库配置","是否添加对数据库访问的支持?",function(flag){
							if(flag==true){jf.request('${webRoot}/dbConfig?code='+record.projectCode);}
						});
					});
				}
			}
		},{
			title:'页面配置',
			format:function(record){
				if(record.configHtml == true){
					return '<a href="${webRoot}/pageConfig?code='+record.projectCode+'">已配置</a>';
				}else if(record.projectType == 'war'){
					return $('<a href="javascript:void(0);">未配置</a>').click(function(){
						jf.modal('页面配置','${webRoot}/pageConfig/type',{code:record.projectCode});
					});
				}else{
					return '不需要';
				}
			}
		},{
			title:'功能插件',
			format:function(record){
				if(record.configPlug == true){
					return $('<a href="javascript:void(0);">已配置</a>').click(function(){
						plugConfigClick.apply(this,[record]);
					});
				}else{
					return $('<a href="javascript:void(0);">未配置</a>').click(function(){
						plugConfigClick.apply(this,[record]);
					});
				}
			}
		},{
			title:'操作',
			icons:[{
				tooltip:'详细',
				icon:'fa-search',
				click:function(record){
					alert(record.projectCode);
				}
			},{
				tooltip:'保存XML',
				icon:'fa-save',
				click:function(record){
					$.getJSON('${webRoot}/project/xml',{code:record.projectCode},function(result){
						if(result.error==1){jf.info("保存成功");}else{jf.error(result.msg);}
					});
				}
			},{
				tooltip:'删除',
				icon:'fa-trash-o',
				click:function(record){}
			},{
				tooltip:'生成代码',
				icon:'fa-bolt',
				click:function(record){
					document.location.href='${webRoot}/project/build?code='+record.projectCode;
				}
			}]
		}]
	})
	
	$('#btnAddProject').click(function(){
		jf.modal('新增代码生成项目','${webRoot}/project/edit',function(result){
			if(result.error==1){
				$('#tableProjectList').jfTable('loadData');
				$(this).modal('hide');
			}else{jf.error(result.msg);}
		});
	})
})
</script>
</body>
</html>